<template>
    <div class="auLayout">
        <div class="infoBox">
            <div class="imgBox">
                <img src="../assets/image/addUserBack.png" />
            </div>
            <div class="form">
                <div class="title">用户注册</div>
                <div class="input">
                    <span>用户名</span>
                    <input placeholder="用户名" v-model="formInfo.uname"/>
                </div>
                <div class="input">
                    <span>密码</span>
                    <input placeholder="密码" v-model="formInfo.password" type="password"/>
                </div>
                <div class="input">
                    <span>联系电话</span>
                    <input placeholder="联系电话" v-model="formInfo.phone" type="number"/>
                </div>
                <button class="button" @click="addUser" :disabled="isDisabled">{{ isDisabled?'请完成输入框内容':'立即注册'}}</button>
                <span class="goLogin">
                    已有账号?
                    <router-link to="/login">前往登录</router-link>
                </span>
            </div>
        </div>
    </div> 
</template>

<script lang="ts" setup>
import { reactive, computed } from 'vue'
import { get,post } from '@/http/axios'
import { ElMessage } from 'element-plus'

const formInfo = reactive({
    uname:null,
    password:null,
    phone:null
})
function addUser() {
    post('/hotel/addHotel',{ 
        name:formInfo.uname,
        code:formInfo.phone,
        password:formInfo.password
     }).then(res => {
        console.log(res);
        ElMessage.success('注册成功，快去登录吧')
     }).catch(err => {
        alert('注册失败')
     })
}
const isDisabled = computed(() => {
    let flag = false
    Object.keys(formInfo).forEach(el => {
        if (!formInfo[el]) {
            flag = true
        }
    })
    return flag
})
</script>

<style lang="scss" scoped>
.auLayout{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    @include flexRowCenter;
    overflow: hidden;
    &::after{
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: url('../assets/image/addUserBack.png');
        background-size: cover;
        background-position: 50%;
        filter: blur(5px);
        scale: 1.2;
        z-index: -1;
        overflow: hidden;
    }
}
.infoBox{
    height: 65%;
    @include flexRowCenter;
    position: relative;
    background: white;
    border-radius: 20px;
    padding: 20px 40px;
    box-sizing: border-box;
    gap: 50px;
    box-shadow: 5px 5px 10px rgb(0, 0, 0, 0.2),
                -5px -5px 10px rgb(0, 0, 0, 0.2),
                -5px 5px 10px rgb(0, 0, 0, 0.2),
                5px -5px 10px rgb(0, 0, 0, 0.2);
}
.imgBox{
    height: 100%;
    border-radius: 8px;
    & img:nth-child(1){
        width: 350px;
        height: 100%;
        border-radius: 8px;
    }
    box-shadow: 5px 5px 10px rgb(0, 0, 0, 0.2),

}
.form{
    position: relative;
    min-width: 350px;
    height: 100%;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 28px;
}
.title{
    color: #409EFF;
    font-size: 30px;
    font-weight: 600;
}
.input{
    position: relative;
    width: 100%;
    height: 35px;
    @include flexRowCenter;
    & span:nth-child(1){
        width: 100px;
        text-align: left;
    }
    & input:nth-child(2){
        outline: none;
        height: 35px;
        width: 100%;
        border: 3px solid var(--el-border-color);
        border-radius: 8px;
    }
}
.button{
    outline: none;
    width: 180px;
    height: 40px;
    border-radius: 4px;
    background: #409EFF;
    border: none;
    color: white;
    @include flexRowCenter;
    &:disabled{
        background: #d1d8e0;
    }
    &:disabled:hover{
        background: #d1d8e0;
    }
    &:hover{
        border: none;
        background: #2d98da;
    }
}
.goLogin{
    position: absolute;
    bottom: 10px;
    right: 20px;
    color: rgb(8, 7, 7);
    & a{
        color: #4b6584;
    }
    & a:hover{
        color: #409EFF;
    }
}
</style>